<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
<title>Gwack Admin</title>
<link href="style.css" rel="stylesheet" type="text/css" />

 <script src="js/jquery-1.js" type="text/javascript"></script>
	<script type="text/javascript" charset="utf-8">
	//tabbed forms box
		$(function () {
			var tabContainers = $('div#forms > div.innerContent'); // change div#forms to your new div id (example:div#pages) if you want to use tabs on another page or div.
			tabContainers.hide().filter(':first').show();
			
			$('ul.switcherTabs a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('ul.switcherTabs li').removeClass('selected');
				$(this).parent().addClass('selected');
				return false;
			}).filter(':first').click();
		});
	</script>



<?php

// Create an array of domain and po names
	$configfile = '/etc/opt/gwack/gwack.xml';
	$obj_xml = simplexml_load_file($configfile);
	foreach ( $obj_xml->server as $server )
	{
		if ($server->type == "po") {
			$pos[] = $server->name;
		}
		if ($server->type == "domain"){
			$doms[] = $server->name;
		}
	}


// Function to load xml file, get variables from xml data and
// create a multi dimensional array to pass back to the caller



function getSettings()
{
	$configfile='/etc/opt/gwack/gwack.xml';
	$xml = simplexml_load_file($configfile);
	$backuppath = $xml->backuppath;
	$mountpath = $xml->mountpath;
	$tarpath = $xml->tarpath;
	$temppath = $xml->temppath;
	$smtphost = $xml->smtphost;
	$emailaddr = $xml->emailaddr;
	$maxinc = $xml->maxinc;
	$startday = $xml->startday;
	$offlinepath = $xml->offlinepath;
	$loglevel = $xml->loglevel;
	$logpath = $xml->logpath;
	$sendlog = $xml->sendlog;
	$gwtimestamp = $xml->gwtimestamp;

	// this sets up the array as key/value pairs.
	// for example the first entry, key is 'backuppath' and value is '/var/gwack/backup'
	// assuming that's what's in the xml file as the value.
	// to access the value from a php point of view, it is:
	//	$settings[backuppath] returns /var/gwack/backup

	$settings = array(
		"backuppath"=>$backuppath,
		"mountpath"=>$mountpath,
		"tarpath"=>$tarpath,
		"temppath"=>$temppath,
		"offlinepath"=>$offlinepath,
		"logpath"=>$logpath,
		"loglevel"=>$loglevel,
		"smtphost"=>$smtphost,
		"emailaddr"=>$emailaddr,
		"maxinc"=>$maxinc,
		"startday"=>$startday,
		"sendlog"=>$sendlog,
		"gwtimestamp"=>$gwtimestamp
		);

	return $settings;
}

// check if teh submit button was hit,	if so, get the POST data
// then modify the xml data with the new data.	see below.

if (isset($_POST['submit_x']))
{
	$configfile='/etc/opt/gwack/gwack.xml';
	$xml = simplexml_load_file($configfile);
	$backuppath=$_POST['backuppath'];
	$mountpath=$_POST['mountpath'];
	$offlinepath=$_POST['offlinepath'];
	$tarpath=$_POST['tarpath'];
	$temppath=$_POST['temppath'];
	$logpath=$_POST['logpath'];
	$loglevel=$_POST['loglevel'];
	$emailaddr=$_POST['emailaddr'];
	$smtphost=$_POST['smtphost'];
	$startday=$_POST['startday'];
	$maxinc=$_POST['maxinc'];
	$sendlog=$_POST['sendlog'];
	$gwtimestamp=$_POST['gwtimestamp'];

	// Here's where we replace the xml values with changes posted via the form.

	$xml->backuppath = $backuppath;
	$xml->mountpath = $mountpath;
	$xml->offlinepath = $offlinepath;
	$xml->tarpath = $tarpath;
	$xml->temppath = $temppath;
	$xml->logpath = $logpath;
	$xml->loglevel = $loglevel;
	$xml->smtphost = $smtphost;
	$xml->emailaddr = $emailaddr;
	$xml->maxinc = $maxinc;
	$xml->startday = $startday;
	$xml->sendlog = $sendlog;
	$xml->gwtimestamp = $gwtimestamp;

	// Write the file back to disk.

	file_put_contents($configfile, $xml->asXML()) or die("ERROR:  Could not save config file");

	// now reload the array from the getSettings function.
	$values = getSettings();

}

//	Call function to get the xml data
//	so to get the xml data,  it would be $values['backuppath']

$values = getSettings();

?>

</head>

<body>
<div id="container">
<?php include('menu.php');?>

<div id="content">
	<div id="leftBox">
		<div class="contentBox">
			<div class="contentBoxTop">
			  <h3>Global Settings</h3>
			</div>
			<div class="innerContent">
			  <form name="submit" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
				<table class="sTable">
				  <tr>
					<td class="firstCol">Backup Path</td>
					<td class="secondCol"><input type="text" name="backuppath" size="28" value="<?php echo $values[backuppath];?>" ></td>
					<td class="firstCol" align="left">Mount Path</td>
					<td class="secondCol"><input name="mountpath" type="text" size="28" value="<?php echo $values[mountpath];?>"></td>			 
					</tr>


					<tr>
					<td class="firstCol">Restore Path</td>
					<td class="secondCol"><input type="text" name="offlinepath" size="28" value="<?php echo $values[offlinepath];?>" ></td>
					<td align="left">Tar Path</td>
					<td><input name="tarpath" type="text" size="28" value="<?php echo $values[tarpath];?>"></td>
					</tr>

					<tr>
					<td>Temp Path</td>
					<td><input type="text" name="temppath" size="28" value="<?php echo $values[temppath];?>" ></td>
					<td>Log Path</td>
					<td><input name="logpath" type="text" value="<?php echo $values[logpath];?>"  size="28"></td>
					</tr>

					<tr><td>SMTP Host</td>
					<td><input name="smtphost" type="text" size="28" value="<?php echo $values[smtphost];?>"></input></td>
					<td>Email Address</td>
					<td><input name="emailaddr" type="text" size="28" value="<?php echo $values[emailaddr];?>"></input></td></tr>
					<tr><td>&nbsp</td></tr>

					<tr><td>Log Level</td>
					<td>Normal <input type="radio" value="Normal" name="loglevel"
					<?php if ($values[loglevel] == "Normal") echo "checked";?> >
						Verbose <input type="radio" value="Verbose" name="loglevel"
					<?php if ($values[loglevel] == "Verbose") echo "checked";?> ></td>

					<td>Send Log File</td>
					<td>Yes<input type="radio" value="Yes" name="sendlog"
					<?php if ($values[sendlog] == 'Yes') echo 'checked';?> >
						No<input type="radio" value="No" name="sendlog"
					<?php if ($values[sendlog] == 'No') echo 'checked';?> ></td></tr>


					<tr><td>Max Incremental Backups</td>
					<td class="secondCol"><select name="maxinc">
				  	<option value="<?php echo $values[maxinc]; ?>" selected="selected"><?php echo $values[maxinc]; ?></option>
					<option value="<?php echo $values[maxinc]; ?>"> --&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </option>
				  <option value="1">1</option>
				  <option value="2">2</option>
				  <option value="3">3</option>
				  <option value="4">4</option>
				  <option value="5">5</option>
				  <option value="6">6</option>
				  <option value="7">7</option>
				  <option value="&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"></option>
				  </select></td>
					<td>Start Day</td>
					<td><select name="startday">
					  <option value="<?php echo $values[startday]; ?>" selected="selected"><?php echo $values[startday]; ?></option>
					  <option value="<?php echo $values[startday]; ?>">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp -- &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</option>
					  <option value="Sunday">Sunday</option>
					  <option value="Monday">Monday</option>
					  <option value="Tuesday">Tuesday</option>
					  <option value="Wednesday">Wednesday</option>
					  <option value="Thursday">Thursday</option>
					  <option value="Friday">Friday</option>
					  <option value="Saturday">Saturday</option>
					</select></td>
					</tr>
					<tr>
					<td>Set GroupWise Time Stamp</td>
					<td>Yes<input type="radio" value="Yes" name="gwtimestamp"
					<?php if ($values[gwtimestamp] == "Yes") echo "checked";?> >
					No<input type="radio" value="No" name="gwtimestamp"
					<?php if ($values[gwtimestamp] == "No") echo "checked";?> ></td>
					</tr>
					<tr><td>&nbsp</td></tr>
					</table>

					<input type="image" value="submit" alt="Submit" name="submit" src="images/save.jpg" />
	
					</form>
				</div>
			</div>
		</div><!-- end of #leftBox -->
		<div id="sidebar" class="rightBoxes">
		  <div class="rightBoxesTop"><h3>Dom - PO Settings</h3></div>
			  <div class="rightContent">
				<ul id="sidebarLinks">
				<?php
				foreach ($doms as $dom) {
					echo "<li><a href='objectsettings.php?name=".$dom."' target='_self' title='".$dom."'>".$dom." Domain Settings</a></li>";
				}
				 foreach ($pos as $po) {
					echo "<li><a href='objectsettings.php?name=".$po."' target='_self' title='".$po."'>".$po." Post Office Settings</a></li>";
				}
				?>
				</ul>
  			</div><!-- end RightContent -->
		</div><!-- end of #sidebar -->

	</div><!-- end of #content -->
	<br class="clearFix" />
</div><!-- end of #container -->


<?php include('footer.html'); ?>

</body>
</html>

